package com.gwz.sys.utils;

import java.util.ArrayList;
import java.util.List;

public class TreeNodeBuilder {
	
	public static List<TreeNode> builder(List<TreeNode> treeNodes,Integer topRootId){
		List<TreeNode> nodes = new ArrayList<>();
		for (TreeNode n1 : treeNodes) {
			if (n1.getPid() == topRootId) {
				nodes.add(n1);
			}
			for (TreeNode n2 : treeNodes) {
				if (n2.getPid() == n1.getId()) {
					n1.getChildren().add(n2);
				}
			}
		}
		return nodes;
	}
}
